import pymysql
import requests
from bs4 import BeautifulSoup
import re

# 目标网页URL
url = 'http://cnki.kmlib.yn.cn/kcms/detail/detail.aspx?dbCode=cjfq&QueryID=46&CurRec=2&filename=JJYJ202110002&dbname=CJFDLAST2021'

# 发送HTTP请求
response = requests.get(url)

# 检查请求是否成功
if response.status_code == 200:
    # 解析HTML内容
    soup = BeautifulSoup(response.text, 'html.parser')
    
    # 提取<h1>标签内容，移除标签和符号
    h1_content = soup.h1.get_text(strip=True)
    h1_content_cleaned = re.sub(r'[^\u4e00-\u9fa5]+', '', h1_content)
    print(f'）: {h1_content_cleaned}')
    
    # 提取<div class="summary pad10">的内容，移除标签和符号
    summary_content = soup.find('div', class_='summary pad10').get_text(strip=True)
    summary_content_cleaned = re.sub(r'[^\u4e00-\u9fa5]+', '', summary_content)
    print(f': {summary_content_cleaned}')
else:
    print(f'请求失败，状态码：{response.status_code}')

# 目标网页URL
url2 = 'http://cnki.kmlib.yn.cn/kcms/detail/detail.aspx?filename=FJSX201801002&dbcode=CJFQ&dbname=CJFD2018'

# 发送HTTP请求
response = requests.get(url2)

# 检查请求是否成功
if response.status_code == 200:
    # 解析HTML内容
    soup = BeautifulSoup(response.text, 'html.parser')
    
    # 提取<h1>标签内容，移除标签和符号
    h1_content = soup.h1.get_text(strip=True)
    h1_content_cleaned = re.sub(r'[^\u4e00-\u9fa5]+', '', h1_content)
    print(f'）: {h1_content_cleaned}')
    
    # 提取<div class="summary pad10">的内容，移除标签和符号
    summary_content = soup.find('div', class_='summary pad10').get_text(strip=True)
    summary_content_cleaned = re.sub(r'[^\u4e00-\u9fa5]+', '', summary_content)
    print(f': {summary_content_cleaned}')
else:
    print(f'请求失败，状态码：{response.status_code}')
